﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Text;


namespace Lawyer.Web.Admin
{
    public partial class admin_postadd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        //protected void Page_Error(object sender, EventArgs e)
        //{

        //    Exception ex = Server.GetLastError();

        //    if (HttpContext.Current.Server.GetLastError() is HttpRequestValidationException)
        //    {

        //        HttpContext.Current.Response.Write("请输入合法的字符串【<a href=\"javascript:history.back(0);\">返回</a>】");

        //        HttpContext.Current.Server.ClearError();

        //    }

        //}   

        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("admin_postlist.aspx");
        }

        private string RichTxtReplace(string str)
        {
            str.Replace("&lt;b&gt;", "<b>");
            str.Replace("&lt;/b&gt;", "</b>");
            str.Replace("&lt;i&gt;", "<i>");
            str.Replace("&lt;/i&gt;", "</i>");
            str.Replace("&lt;/i&gt;", "<h1>");
            str.Replace("&lt;/i&gt;", "</h1>");
            str.Replace("&lt;/i&gt;", "<h2>");
            str.Replace("&lt;/i&gt;", "</h2");
            str.Replace("&lt;/i&gt;", "<h3>");
            str.Replace("&lt;/i&gt;", "</h3>");
            return str;
        }

        protected void btnPostAdd_Click(object sender, EventArgs e)
        {

          
            string strErr = "";
            
            if (this.txtTile.Text.Trim().Length == 0)
            {
                strErr += "Tile cannot be empty！\\n";
            }
            if (this.txtDetail.Text.Trim().Length == 0)
            {
                strErr += "Detail cannot be empty！\\n";
            }



            string PostID = Guid.NewGuid().ToString();
            string Tile = this.txtTile.Text;
            StringBuilder Detail= new StringBuilder(HttpUtility.HtmlEncode(txtDetail.Text));
           // string Detail = this.txtDetail.Text;
            int Status = 0;
            string CreatedBy = Session["UserID"].ToString(); ;
            DateTime CreatedDate = DateTime.Now;
            string UpdatedBy = Session["UserID"].ToString(); ;
            DateTime UpdatedDate = DateTime.Now;

            Lawyer.Model.PostInfo model = new Lawyer.Model.PostInfo();
            model.PostID = PostID;
            model.Tile = Tile;
            model.Detail = Detail.ToString();
            model.Status = Status;
            model.CreatedBy = CreatedBy;
            model.CreatedDate = CreatedDate;
            model.UpdatedBy = UpdatedBy;
            model.UpdatedDate = UpdatedDate;

            Lawyer.BLL.PostInfo bll = new Lawyer.BLL.PostInfo();
            bll.Add(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "success！", "admin_postlist.aspx");
        }
    }
}
